<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        h1 {
            font-size: 30px;
        }
    </style>
</head>

<body>
    <!-- 以设置rem为例 -->
    <h1>rem:<span id="fontSize"></span></h1>
    <script src="js/index.js"></script>
    <script>
        ; (function () {
            var supportevent = "onorientationchange" in window ? "orientationchange" :"resize";
          
            // var supportevent = "onorientationchange" in window ? "orientationchange" : "resize";
            window.onload = function () {
                //初次设置rem
                setRem();
            }

            //监听可视窗口的缩放事件或者移动端的屏幕方向事件
            window.addEventListener(supportevent, debounce(setRem));

            function setRem(p = 100 / 375) {
                var clientW = document.documentElement.offsetWidth;
                document.documentElement.style.fontSize = p * clientW + "px";
                document.querySelector("#fontSize").innerHTML = p * clientW + "px";
            }
        })();
    </script>
</body>

</html>